package com.pg.agent.engine.client.common.enums;

import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 提示词模板参数枚举
 *
 * @author huhuaping
 * @date 2023/12/4 13:59
 */
public enum PromptVariableEnum {

    /**
     * 类型0：内置，1：系统变量，2：自定义变量
     * 系统变量, code, 说明, agent切换模板, state切换模板
     */
    SUMMARY(0, 1,"summary", "短记忆（对话总结）",2,"","角色:xx   内容:xxx"),

    LAST_NAME(0, 2,"last_name", "最后执行Agent",2,"", "xx"),

    QUERY(0, 3,"query", "最后对话", 2,"","姓名：xx，角色：xx，说话内容："),

    CHAT_HISTORY_MESSAGE(0,4, "chat_history_message", "对话历史", 2,"","姓名：xx，角色：xx，说话内容：xxx"),

    RELEVANT_HISTORY(0, 5,"relevant_history", "相关记录",2,"", "姓名：xx，角色：xx，说话内容：xxx"),

    ENVIRONMENT_PROMPT(1, 6,"environment_prompt", "背景描述",2,"", ""),

    //JUDGE_SYSTEM_PROMPT(1, 7,"judge_system_prompt", "背景指令",2,"", ""),

    //call_last_prompt
    //ALLOCATE_PROMPT(0, 8,"allocate_prompt", "agent分配", 2,"","他的主要任务是:%s，如果当前应该是%s说话，则输出<end>%s</end>。"),
    ;

    /**
     * 类型
     */
    private Integer type;
    /**
     * 系统属性ID
     */
    private Integer paramId;
    /**
     * 系统属性编码
     */
    private String paramCode;
    /**
     * 系统属性名称
     */
    private String paramName;
    /**
     * 系统属性说明
     */
    private String paramDesc;
    /**
     * 系统属性数据类型
     */
    private Integer paramType;
    /**
     * 案例
     */
    private String example;

    PromptVariableEnum() {

    }

    PromptVariableEnum(Integer type, Integer paramId, String paramCode, String paramName, Integer paramType, String paramDesc, String example) {
        this.type = type;
        this.paramId = paramId;
        this.paramCode = paramCode;
        this.paramName = paramName;
        this.paramType = paramType;
        this.paramDesc = paramDesc;
        this.example = example;
    }

    public static String getCodeByValue(Integer value) {

        PromptVariableEnum controllerTypeEnum = Arrays.stream(values()).filter(e -> e.type.equals(value)).findFirst().orElse(null);

        return controllerTypeEnum == null ? "" : controllerTypeEnum.paramCode;
    }

    /**
     * 获取Agent切换提示词模板参数
     *
     * @return
     */
    public static List<PromptVariableEnum> listAgentSwitchVariable() {

        List<PromptVariableEnum> agentParam = new ArrayList<>();
        agentParam.add(ENVIRONMENT_PROMPT);
        agentParam.add(LAST_NAME);
        agentParam.add(QUERY);
        agentParam.add(CHAT_HISTORY_MESSAGE);
        agentParam.add(RELEVANT_HISTORY);
        agentParam.add(SUMMARY);

        return agentParam;
    }

    /**
     * 获取state切换提示词模板参数
     *
     * @return
     */
    public static List<PromptVariableEnum> listStateSwitchVariable() {
        List<PromptVariableEnum> stateParam = new ArrayList<>();
        stateParam.add(ENVIRONMENT_PROMPT);
        stateParam.add(SUMMARY);
        stateParam.add(QUERY);
        stateParam.add(CHAT_HISTORY_MESSAGE);
        stateParam.add(RELEVANT_HISTORY);
        return stateParam;
    }

    public static Map<String, String> getAllExample() {
        List<PromptVariableEnum> list = Arrays.asList(PromptVariableEnum.values());
        Map<String, String> map = list.stream().collect(Collectors.toMap(PromptVariableEnum::getParamCode, PromptVariableEnum::getExample));
        return map;
    }


    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getParamId() {
        return paramId;
    }

    public void setParamId(Integer paramId) {
        this.paramId = paramId;
    }

    public String getParamCode() {
        return paramCode;
    }

    public void setParamCode(String paramCode) {
        this.paramCode = paramCode;
    }

    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    public String getParamDesc() {
        return paramDesc;
    }

    public void setParamDesc(String paramDesc) {
        this.paramDesc = paramDesc;
    }

    public Integer getParamType() {
        return paramType;
    }

    public void setParamType(Integer paramType) {
        this.paramType = paramType;
    }

    public String getExample() {
        return example;
    }

    public void setExample(String example) {
        this.example = example;
    }
}
